<template>
  <div class="register">
    <van-nav-bar
      class="nav-bar"
      title="账号注册"

    />

    <van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="username"
    label="用户名"
    placeholder="用户名"
    :rules="[
    { required: true, message: '请填写用户名' },
    {pattern: /^\w{5,8}$/,message: '宝贝,用户名为3~8位哦~~~'}
    ]"
  />
  <van-field
    v-model="password"
    type="password"
    name="password"
    label="密码"
    placeholder="密码"
    :rules="[
    { required: true, message: '请填写密码' },
    {pattern: /^\w{6,}$/,message: '宝贝,密码至少为6位哦~~~'}
    ]"
  />
  <div style="margin: 16px;">
    <van-button  block type="info" native-type="submit" color="#ffc0cb">注册</van-button>
  </div>
</van-form>
<router-link class="link" to="/login">已有账号,去登录</router-link>
 <div class="picture">
      <img
        src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg2.huashi6.com%2Fimages%2Fresource%2F2021%2F08%2F02%2F9167257h5p0.png%3FimageMogr2%2Fquality%2F75%2Finterlace%2F1%2Fthumbnail%2F700x%26gt%3B%2Fformat%2Fjpeg&refer=http%3A%2F%2Fimg2.huashi6.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1670246195&t=df8338dcd6e31bb60732d81050aa73c0"
        alt=""
      />
    </div>
  </div>
</template>

<script>
import { register } from '@/api/user'
export default {
  name: 'register-page',
  methods: {
    async onSubmit (values) {
      const res = await register(values)
      console.log(res)

      if (res.status === 200) {
        this.$toast.success('注册成功')
        setTimeout(() => {
          this.$router.push('/login')
        }, 1000)
      } else {
        this.$toast.fail(res.description)
      }
    }

  },
  data () {
    return {
      username: '',
      password: ''
    }
  }
}
</script>

<style lang='less' scoped>
body {
  background-color: #fff!important;
}
.nav-bar{
  margin-bottom: 20px;
}
.picture {
  width: 200px;
  height: 300px;
}
img {
  width: 100%;
}
.link {
  display: block;
  text-align: center;
  font-size: 14px;
  color: #999;
}
</style>
